<template>
  <view class="page">
<!--    <u-navbar bgColor='#4871C0' :titleStyle="{ color: '#FFF'}" title="签到" leftIconColor="#FFF"-->
<!--              @rightClick="rightClick" :autoBack="true"  >-->
<!--    </u-navbar>-->
    <view class="content">
      <view class="imgurl">
        <u--image :src="userinfo.avatar||'https://cdn.uviewui.com/uview/album/1.jpg'" shape="circle" width="200rpx"
                                       height="200rpx">
        </u--image>
      </view>
      <view class="imgtitle">{{ userinfo.nickname }}</view>
      <view class="write_item" v-show="list_item.files&&list_item.files.fullurl">
        <img :src="list_item.files.fullurl" alt="">
      </view>
    </view>
    <view class="button write_btn" @click="addwriteName()">
      {{ write_name_id?'修改手写签名':'添加手写签名' }}
    </view>
    <view class="button" @click="sign()">
      签到
    </view>
  </view>
</template>

<script>
import {goInfoToken, goSign, goInfos, goSignNew} from "../../api/signApi";
import {
  meetSignatureList
} from "@/api/autograph.js"
import {
  mapActions
} from 'vuex';
export default {
  data() {
    return {
      token:uni.getStorageSync('token')||'',
      userinfo:{},
      meet_id:'',
      write_name_id:'',
      list_item: {
        files:{
          fullurl:''
        }
      }
    }
  },
  onLoad(options) {
    uni.setStorageSync('sign',this.$route.path)
    if(!this.token){
      if(this.getUrlKey("code")){
        console.log(window.location,this.getUrlKey("code"));

        this.getinfo(this.getUrlKey("code"))
      }else{
        setTimeout(()=>{
          let params = {
            token:this.token,
            path:'/#'+this.$route.path
          }
          this.getUserInfo(params)
        },2000)
      }
    }
    else{
      goInfos({token:this.token}).then(res => {
        this.isLoading = false;
        console.log(res)
        if(res.code == 1){
          this.userinfo = res.data
        }
      })
    }
    this.meet_id = options.id?options.id:options.meet_id
    this.write_name_id = options.write_name_id
    this.getwrite_list()
  },
  methods: {
    ...mapActions(['getUserInfo']),
    getinfo(code){
      goInfoToken(  {code:code}).then(res => {
        this.isLoading = false;
        console.log(res)
        if(res.code == 1){
          uni.setStorageSync('token',res.data.userinfo.token)
          this.userinfo = res.data.userinfo
        }
      })
    },
    getUrlKey(name) {
      let arr = window.location.href.split('&');
     let arr1 =  arr[0].split('=');
     return arr1[1]
    },
    addwriteName(){
      uni.navigateTo({
        url: '/pages/tabbar-1-detial/sign/autograph?meet_id=' + this.meet_id+'&type_sigin=1'
      });
    },
    getwrite_list(){
      meetSignatureList().then(res => {

        let list = res.data;
        list.forEach((item)=>{
          if(item.id == this.write_name_id){
            this.list_item = item
          }
        })
        console.log(this.list_item,"this.list")
      })
    },
    sign(){
      if(!this.write_name_id){
        uni.showToast({
          title: '请先添加手写签名',
          icon: 'none',
          duration: 1000
        });
        return
      }
      let params = {
        token:this.token,
        sign_way:2,
        meet_id:this.meet_id,
        qiming_id:this.write_name_id
      }
      goSignNew(params).then(res => {
        this.isLoading = false;
        console.log(res)
        uni.showToast({
          title: res.msg,
          icon: 'none',
          duration: 1000
        });
        setTimeout(()=>{
          uni.navigateTo({
            url: '/pages/tabbar-1-detial/meetingDetails/meetingDetails?id=' + this.meet_id
          });
        },1000)

      })
    }
  }
}
</script>

<style>
.page{
  /* padding: 0 20rpx;	 */
  background-color: #f5f6f8;
  min-height: 100vh;
}
.content{
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  height: 900rpx;

}
.imgtitle{
  font-size: 40rpx;
  font-family: Microsoft YaHei;
  font-weight: bold;
  color: #3B3B3F;
  margin-top: 50rpx;
}
.button{
  background: #4871C0;
  border-radius: 8rpx;
  opacity: 1;
  font-size: 28rpx;
  font-weight: 600;
  color: #FFFFFF;
  text-align: center;
  padding: 20rpx 0;
  position:fixed;
  margin:0 auto;
  width: calc(100% - 120rpx);
  bottom: 22%;
  left: 60rpx;
}
.write_btn{
  bottom: 29%;
}
.write_item{
  width: 208rpx;
  height: 208rpx;
  border: 2rpx solid #333;
  border-radius: 20rpx;
  margin: 60rpx auto;
}
.write_item img{
  width: 208rpx;
  height: 208rpx;
}
</style>
